package com.ruoyi.web.controller.qqLoginAndPayByHTQ;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

import com.ruoyi.User.wxpay.OtherUtils;



/**
 * @author kk
 * 微信提现
 */
public class QQPayExtract {

    /*public static void main(String[] args) throws Exception {
        //提现金额(单位:元)
        String result = "0.01";
        Map<String, String> map = new HashMap<String, String>();

        //元转换为分,微信支付已分为单位
        BigDecimal sumAmount = new BigDecimal(result);
        //乘以100，转换为分
        BigDecimal transAmt = sumAmount.multiply(new BigDecimal(100)); 



        //订单号
        String Order = "WH201909050822336743";
        //随机字符串
        map.put("nonce_str",OtherUtils.getNonceStr().toString());
        //openid("c从数据库中查询")
        //map.put("openid",openid.get(0).getUserlevel());
        map.put("openid","outT15R0CmJ-MpQklSn6i0x6D-eE");
        //金额
        map.put("amount","30");
        ////企业付款操作说明信息
        map.put("desc","提现测试");
        map.put("partner_trade_no",Order);
        

        //调用支付
        String returnInfo =  WeChatWithdrawUtils.withdrawRequestOnce(map,3000,3000,true);
        Map<String,String> resultMap = OtherUtils.readStringXmlOut(returnInfo);

        if(resultMap.containsKey("result_code") && "SUCCESS".equals(resultMap.getOrDefault("result_code",""))){
            System.out.println("提现成功");
            System.out.println("返回结果："+returnInfo);
        }else{
            System.out.println("提现失败");
            System.out.println("返回结果："+returnInfo);
        }


    }*/
    
	public static String deptToUser(String account, String openId, String desc,
			String orderId) throws Exception {
		if("0".equals(account)) {
			return "退回金额为0，不进行退回操作";
		} else {
		Map<String, String> map = new HashMap<String, String>();
		// 元转换为分,QQ支付已分为单位
		BigDecimal sumAmount = new BigDecimal(account);
		// 乘以100，转换为分
		BigDecimal transAmt = sumAmount.multiply(new BigDecimal(100));
		int accountTrue=transAmt.intValue();
		String jine=String.valueOf(accountTrue);
		// 订单编号
		String Order = orderId + "3";
		// 随机字符串
		map.put("nonce_str", OtherUtils.getNonceStr().toString());
		// openid("c从数据库中查询")
		// map.put("openid",openid.get(0).getUserlevel());
		map.put("openid", openId);
		// 金额
		map.put("amount",jine );
		// //企业付款操作说明信息
		map.put("desc", desc);
		map.put("orderId", Order);
		// 调用支付
		String returnInfo = QQPayWithdrawUtils.departPayToUser(map, 3000,
				3000, true);
		Map<String, String> resultMap = OtherUtils.readStringXmlOut(returnInfo);

		if (resultMap.containsKey("result_code")
				&& "SUCCESS".equals(resultMap.getOrDefault("result_code", ""))) {
			System.out.println("提现成功");
			System.out.println("返回结果：" + returnInfo);
		} else {
			System.out.println("提现失败");
			System.out.println("返回结果：" + returnInfo);
		}
		return returnInfo.toString();
	}
	}
}

